package cn.wolfcode.redis.service.impl;

import cn.wolfcode.redis.service.IArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class ArticleServiceImpl implements IArticleService {
    @Autowired
    private StringRedisTemplate template;
    @Override
    public Integer incr(Long id) {
        // key
        String key = "article_viewnum"+id.toString();
        // value
        Long increment = template.opsForValue().increment(key);
        // 把value的值转换为int类型
        return increment.intValue();
    }
}
